function TreeNode(val, left, right){
    this.val = val == undefined ? 0 : val
    this.left = left == undefined ? null : left
    this.right = right == undefined ? null : right
}

function createTree(){
    const root = new TreeNode(3)
    root.left = new TreeNode(9)
    root.right = new TreeNode(20)
    root.right.left = new TreeNode(15)
    root.right.right = new TreeNode(7)
    return root
}



const treeRoot = createTree()
// console.log(treeRoot)  // 打印根节点

let maxDepth = function(root){
    // 如果当前节点为空，返回0
    if (!root) {
        return 0;
    }

    // 递归计算左子树的最大深度
    const leftDepth = maxDepth(root.left);

    // 递归计算右子树的最大深度
    const rightDepth = maxDepth(root.right);

    // 返回左子树和右子树的最大深度中的较大值加1
    return Math.max(leftDepth, rightDepth) + 1;
}


console.log(maxDepth(treeRoot))